﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DataAccess.Classes;
using DataAccess;

namespace Webmau.Controls
{
    public partial class DanhSachNhaTro : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PopulateControls();
            }
        }

        private void PopulateControls()
        {
            int howManyPages = 0;
            string Id = Request.QueryString["IDDiaDiem"] ?? "";
            string page = Request.QueryString["Page"] ?? "1";
            string timkiemString = Request.QueryString["StringText"] ?? "";

            string firstPageUrl = "";
            string pagerFormat = "";
            if (Id != "")
            {
                dlDanhSachNhaTro.DataSource = PhongTro1.LayDanhSachTheoIDDiaDiem(Id, page, out howManyPages);
                dlDanhSachNhaTro.DataBind();
                firstPageUrl = Link.ToDiaDiem(Id);
                pagerFormat = Link.ToDiaDiem(Id, "{0}");
            }

            else if (timkiemString != "")
            {
                dlDanhSachNhaTro.DataSource = PhongTro1.TimKiem(timkiemString, page, out howManyPages);
                dlDanhSachNhaTro.DataBind();

                firstPageUrl = Link.ToTimKiem(timkiemString, "1");
                pagerFormat = Link.ToTimKiem(timkiemString, "{0}");

            }
            else
            {
                dlDanhSachNhaTro.DataSource = PhongTro1.LayTheoTinhTrang(page, out howManyPages);
                dlDanhSachNhaTro.DataBind();
                firstPageUrl = Link.ToDanhMucPhongTro("1");
                pagerFormat = Link.ToDanhMucPhongTro("{0}");
            }
            pagerTop.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, true);
            pagerBottom.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, true);
        }
    }
}